structure Tokens : SLP_TOKENS =
struct

type pos = int;

datatype elt = Print
	     | If
	     | Then
	     | Else
	     | Divide
	     | Times
	     | Minus
	     | Plus
	     | Less
	     | LessEqual
	     | Greater
	     | GreaterEqual
	     | Equal
	     | LParen
	     | RParen
	     | ColonEq
	     | Semicolon
	     | Comma
	     | Int of int
	     | Bool of bool
	     | Id of string
	     | Eof

type token = (elt * pos * pos);
type keyword = pos * pos -> token;

local fun unlex Print		= "PRINT"
	| unlex If		= "IF"
	| unlex Then		= "THEN"
	| unlex Else		= "ELSE"

	| unlex Divide		= "DIVIDE"
	| unlex Times		= "TIMES"
	| unlex Minus		= "MINUS"
	| unlex Plus		= "PLUS"

	| unlex Less		= "LESS"
	| unlex LessEqual	= "LESSEQUAL"
	| unlex Greater		= "GREATER"
	| unlex GreaterEqual	= "GREATEREQUAL"
	| unlex Equal           = "EQUAL"

	| unlex LParen		= "LPAREN"
	| unlex RParen		= "RPAREN"
			 
	| unlex ColonEq		= "COLONEQ"
	| unlex Semicolon	= "SEMICOLON"
	| unlex Comma		= "COMMA"
			
	| unlex (Int z)		= "INT(" ^ Int.toString(z) ^")"
	| unlex (Bool b)	= "BOOL(" ^ (if b then "true" else "false") ^ ")"
	| unlex (Id s)		= "ID(" ^ s ^")"
			   
	| unlex Eof		= "EOF"

in fun show (e, i, j) = unlex e (* ^ Int.toString i ^ "--" ^ Int.toString (i+j) *)
end;

fun PRINT (i, j)	= (Print, i, j);
fun IF (i, j)		= (If, i, j);
fun THEN (i, j)		= (Then, i, j);
fun ELSE (i, j)		= (Else, i, j);
fun DIVIDE (i, j)	= (Divide, i, j);
fun TIMES (i, j)	= (Times, i, j);
fun MINUS (i, j)	= (Minus, i, j);
fun PLUS (i, j)		= (Plus, i, j);
fun LESS (i, j)		= (Less, i, j);
fun LESSEQUAL (i, j)	= (LessEqual, i, j);
fun GREATER (i, j)	= (Greater, i, j);
fun GREATEREQUAL (i, j) = (GreaterEqual, i, j);
fun EQUAL (i, j)	= (Equal, i, j);
fun LPAREN (i, j)	= (LParen, i, j);
fun RPAREN (i, j)	= (RParen, i, j);
fun COLONEQ (i, j)	= (ColonEq, i, j);
fun SEMICOLON (i, j)	= (Semicolon, i, j);
fun COMMA (i, j)	= (Comma, i, j);
fun INT (z, i, j)	= (Int z, i, j);
fun BOOL (b, i, j)	= (Bool b, i, j);
fun ID (s, i, j)	= (Id s, i, j);
fun EOF (i, j)		= (Eof, i, j);

end
